package com.yan.demo;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author taoge
 * @Date 2024/8/12 9:15
 * @Description
 */
public class ThreadPoolDemo1 {
    public static void main(String[] args) {
        CountDownLatch countDownLatch = new CountDownLatch(10000);
        ExecutorService threadpool = Executors.newFixedThreadPool(5);
        long start = System.currentTimeMillis();

        Runnable runnable = new Runnable() {
           @Override
           public void run() {
               System.out.println(Thread.currentThread().getName() + "已执行");
               countDownLatch.countDown();
           }
       };

        for (int i = 0; i < 10000; i++) {
            Future<String> xixi = threadpool.submit(runnable, "xixi");
        }

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        long end = System.currentTimeMillis();

        System.out.println("花费了" + (end - start) + "毫秒");

    }

}
